package service

import (
	"go_stu_gin/config"
	"go_stu_gin/models"
	"go_stu_gin/util"
	viewmodel "go_stu_gin/view_model"

	"github.com/gin-gonic/gin"
)

type BaseService struct{}

func (b *BaseService) BasePing(ctx *gin.Context) (int, *viewmodel.BasePingOutput, error) {
	out := &viewmodel.BasePingOutput{}
	var input viewmodel.BasePingInput
	if err := util.DefaultBindParams(ctx, &input); err != nil {
		return util.NOSERVER, out, err
	}
	out.Name = input.Name
	out.Age = input.Age
	return util.SUCCESS, out, nil
}

func (b *BaseService) GetUserInfo(ctx *gin.Context) (int, interface{}, error) {
	var out interface{}
	tx := config.MyCtx.Db
	var input viewmodel.GetUserInfoInput
	if err := util.DefaultBindParams(ctx, &input); err != nil {
		return util.NOSERVER, out, err
	}
	userDao := &models.UsersDao{Id: input.Id}
	if err := userDao.First(tx); err != nil {
		return util.NOTFOUND, out, err
	}
	out = userDao
	return util.SUCCESS, out, nil
}
